package cn.com.lsy.product.lepao.service.impl;

import cn.com.lsy.product.lepao.common.Constant;
import cn.com.lsy.product.lepao.model.dao.LpConsoleLogTblMapper;
import cn.com.lsy.product.lepao.model.entities.LpConsoleLogTbl;
import cn.com.lsy.product.lepao.service.ILoggerService;
import cn.com.lsy.product.lepao.util.CommonFunctionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;

@Service
public class LoggerService implements ILoggerService {

    @Autowired
    LpConsoleLogTblMapper lpConsoleLogTblMapper;

    @Override
    public boolean insert(int userId, String type, String content, String ip) {

        LpConsoleLogTbl lpConsoleLogTbl = new LpConsoleLogTbl();
        lpConsoleLogTbl.setContent(content);
        try {
            lpConsoleLogTbl.setCreatedAt(CommonFunctionUtil.getDateTime(Constant.formatType.second));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        lpConsoleLogTbl.setIp(ip);
        lpConsoleLogTbl.setOptType(type);
        lpConsoleLogTbl.setUserId(userId);

        if (lpConsoleLogTblMapper.insertSelective(lpConsoleLogTbl) > 0) {
            return true;
        } else {
            return false;
        }

    }
}
